<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>牵头考核部门主页</title>
    <link href="lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="lib/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="lib/website/tb-page.css" rel="stylesheet">
    <style type="text/css">
    .form-horizontal .control-label {
        text-align: left;
    }
    </style>
</head>

<body>
    <div class="container-fluid">
        <div class="row header">
            <div class="col-md-8 col-sm-8">
                <h3>辽宁环保攻坚考核系统</h3>
            </div>
            <div class="col-md-4 col-sm-4 ">
                <h6 class="text-right">欢迎您! XX管理员@XXX.com</h6>
            </div>
        </div>
        <div class="row">
            <nav class="navbar navbar-default">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-top">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">辽宁环保攻坚考核系统</a>
                </div>
                <div class="collapse navbar-collapse" id="navbar-top">
                    <ul class="nav navbar-nav">
                        <li><a href="index.html">考核结果</a></li>
                        <li class="active"><a href="assess-department.html">考核评分</a></li>
                        <li><a href="assessed.html">数据上报</a></li>
                        <li><a href="dataAnalysis.html">数据分析</a></li>
                        <li><a href="#">用户管理</a></li>
                    </ul>
                </div>
            </nav>
        </div>
        <div class="content">
            <div class="row">
                <div class="col-md-12">
                    <form class="form-horizontal">
                        <fieldset>
                            <div class="form-group">
                                <div class="col-md-1">
                                    <label for="inputEmail" class="control-label"><i class="glyphicon glyphicon-play text-primary"></i> 被考核单位</label>
                                </div>
                                <div class="col-md-11">
                                    <div class="radio">
                                        <label><input type="radio" name="radios3" value="" checked=""> 全部城市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="沈阳市"> 沈阳市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="大连市"> 大连市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="鞍山市"> 鞍山市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="抚顺市"> 抚顺市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="本溪市"> 本溪市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="丹东市"> 丹东市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="锦州市"> 锦州市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="营口市"> 营口市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="阜新市"> 阜新市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="辽阳市"> 辽阳市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="铁岭市"> 铁岭市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="朝阳市"> 朝阳市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="盘锦市"> 盘锦市</label>&nbsp;&nbsp;
                                        <label><input type="radio" name="radios3" value="葫芦岛市"> 葫芦岛市</label>&nbsp;&nbsp;
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-1">
                                    <label for="inputEmail" class="control-label"><i class="glyphicon glyphicon-play text-primary"></i> 考核大类</label>
                                </div>
                                <div class="col-md-11">
                                    <label class='checkbox-ex'><input type="checkbox" class="sort" value="大气污染防治"> 大气污染防治</label>&nbsp;&nbsp;
                                    <label class='checkbox-ex'><input type="checkbox" class="sort" value="水污染防治"> 水污染防治</label>&nbsp;&nbsp;
                                    <label class='checkbox-ex'><input type="checkbox" class="sort" value="土壤污染防治"> 土壤污染防治</label>&nbsp;&nbsp;
                                    <label class='checkbox-ex'><input type="checkbox" class="sort" value="农业农村污染治理"> 农业农村污染治理</label>&nbsp;&nbsp;
                                    <label class='checkbox-ex'><input type="checkbox" class="sort" value="主要污染物减排"> 主要污染物减排</label>&nbsp;&nbsp;
                                    <label class='checkbox-ex'><input type="checkbox" class="sort" value="生态红线和自然保护区"> 生态红线和自然保护区</label>&nbsp;&nbsp;
                                    <label class='checkbox-ex'><input type="checkbox" class="sort" value="环境风险和信访办理"> 环境风险和信访办理</label>&nbsp;&nbsp;
                                    <label class='checkbox-ex'><input type="checkbox" class="sort" value="生态环境治理"> 生态环境治理</label>&nbsp;&nbsp;
                                    <label class='checkbox-ex'><input type="checkbox" class="sort" value="执法队伍和执法工作"> 执法队伍和执法工作</label>&nbsp;&nbsp;
                                    <label class='checkbox-ex'><input type="checkbox" class="sort" value="生态制度建设和保护责任落实">
                                        生态制度建设和保护责任落实</label>&nbsp;&nbsp;
                                    <label class='checkbox-ex'><input type="checkbox" value="近岸海域综合治理"> 近岸海域综合治理</label>&nbsp;&nbsp;
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-1 control-label"><i class="glyphicon glyphicon-play text-primary"></i>
                                    是否上报</label>
                                <div class="col-md-3">
                                    <div class="radio">
                                        <label><input type="radio" name="radios1" value=1> 已经上报 </label>
                                        <label><input type="radio" name="radios1" value=0> 未上报 </label>
                                        <label><input type="radio" name="radios1" value=2 checked=""> 全部 </label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-1 control-label"><i class="glyphicon glyphicon-play text-primary"></i>
                                    是否评分</label>
                                <div class="col-md-3">
                                    <div class="radio">
                                        <label><input type="radio" name="radios2" value=1> 已经评分 </label>
                                        <label><input type="radio" name="radios2" value=0> 未评分 </label>
                                        <label><input type="radio" name="radios2" value=2 checked=""> 全部 </label>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="well well-sm info">有<a href="javascript:void(0);" id="count">25</a>个被考核单位的<a href="javascript:void(0);" id="count1">25</a>个考核指标未评分, 请及时评分</div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <table class="table table-striped table-hover table-bordered" id="table">
                    </table>
                </div>
            </div>
            <div class="row" style="margin-top: 10px;">
                <div class="col-md-12">
                    <button class="btn btn-primary" id="save">保存</button>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="lib/jquery/jquery.1.10.2.min.js"></script>
<script src="lib/bootstrap/js/bootstrap.min.js"></script>
<script src="lib/bootstrap-table/bootstrap-table.min.js"></script>
<script src="lib/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="lib/website/function.js"></script>
<script src="lib/website/interface.js"></script>
<script type="text/javascript">
/**
 * 获取复选框值
 * @param
 * @returns {*}
 */
function getCheckBoxVal() { //jquery获取所有选中的复选框的值 
    var checkValue = [];
    $(".checkbox-ex").find('input:checkbox').each(function() { //遍历所有复选框
        if ($(this).prop('checked') == true) {
            if (checkValue['tScoringTable']) {
                if ($(this).attr('class') == 'sort') {
                    checkValue['tScoringTable'] = checkValue['tScoringTable'] + ',' + $(this).val();
                }
            } else {
                if ($(this).attr('class') == 'sort') {
                    checkValue['tScoringTable'] = $(this).val();
                }
            }
        }
    });
    return checkValue;
}

function getScoreList() {
    $('.editScore').each(function(key, value) {
        var values = $(this).val()
        var keys = $(this).attr("data-id")
    })

}

/**
 * 获取单选框值
 * @param $this
 * @returns {*}
 */
function getRadioVal() {
    var result = {}
    result.scoreFinish = $("input[name='radios1']:checked").val();
    result.reportFinish = $("input[name='radios2']:checked").val();
    result.areaName = $("input[name='radios3']:checked").val();
    return result
}

function getList(a, b) {
    $('#table').bootstrapTable({
        url: 'http://39.98.42.158/manage/getBaseScoreList', //请求后台的URL（*）
        method: 'get', //请求方式（*）
        //toolbar: '#toolbar',                //工具按钮用哪个容器
        cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: false, //是否显示分页（*）
        sortable: false, //是否启用排序
        sortOrder: "asc", //排序方式
        // queryParams: oTableInit.queryParams,//传递参数（*）
        sidePagination: "client", //分页方式：client客户端分页，server服务端分页（*）
        pageNumber: 1, //初始化加载第一页，默认第一页
        pageSize: 50, //每页的记录行数（*）
        pageList: [10, 25, 50, 100], //可供选择的每页的行数（*）
        search: false, //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
        strictSearch: false,
        showColumns: false, //是否显示所有的列
        showRefresh: false, //是否显示刷新按钮
        minimumCountColumns: 2, //最少允许的列数
        clickToSelect: false, //是否启用点击选中行
        height: 500, //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
        uniqueId: "ID", //每一行的唯一标识，一般为主键列
        showToggle: false, //是否显示详细视图和列表视图的切换按钮
        cardView: false, //是否显示详细视图
        detailView: false, //是否显示父子表
        dataType: 'json',
        queryParams: function(params) {
            var queryData = {}; //如果没有额外的查询参数的话就新建一个空对象，如果有的话就先装你的查询参数
            //然后增加这两个
            // queryData.limit = params.limit;
            // queryData.offset = params.offset;
            // queryData.pageNo = (params.offset / params.limit) + 1;
            // queryData.pageSize = params.limit;
            if (a) {
                queryData.tScoringTableName = a
            }
            if (b && b.hasOwnProperty('areaName')) {
                queryData.areaName = b.areaName
            }
            if (b && b.hasOwnProperty('reportFinish')) {
                queryData.reportFinish = b.reportFinish
            }
            if (b && b.hasOwnProperty('scoreFinish')) {
                queryData.scoreFinish = b.scoreFinish
            }

            return queryData; //这个就是向服务端传递的参数对象
        },
        formatLoadingMessage: function() { // 表格生成过程中执行的方法
            return '请稍等，正在加载中...'; // 返回一串等待文字
        },
        formatNoMatches: function() { // 没有匹配的结果执行的方法
            return '无符合条件的记录'; // 返回一串提示文字
        },
        onLoadSuccess: function(data) {

        },
        responseHandler: function(res) {
            if (res.data) {
                var result = [];
                var rows = res.data.rows
                var newrow = [];
                // console.log(rows)
                $.each(rows, function(index, value) {
                    if (!value.hasOwnProperty('score')) {
                        value.score = 0
                    }
                    // var  score="<input name='' class='editScore' value='"+value.score+"' data-id='"+value.tScoringTableId+"'/>"
					
					//{modify by wuguofang 20181205 for 调整下载url乱码问题 begin
                    //var download = '<a href=http://39.98.42.158/manage/fileDownload?areaName=' + value.areaName + '>下载</a>'
					var searchText = 'assessmentDepartmentName='+value.areaName+'&assessmentIndicatorsName='+value.assessmentIndicatorsName;
                    if(value.reportFinish=='未上报'){
                        var	download="<a class='u-upload' href=\"#\" onclick=\"alert('未上报！')\">"+"下载"+"</a>";
                    }else{
                        var	download="<a class='u-upload' href=\"#\" onclick=\"sentMessage('"+searchText+"')\">"+"下载"+"</a>";
                    }

					//modify by wuguofang 20181205 for 调整下载url乱码问题 end}
					if(value.score){
                        var score = value.score+" <a onclick='change(this)'  data-max='" + value.scoreMax + "' data-id='" + value.tScoringTableId + "' data-value='"+value.score+"'>编辑</a>";
                        // var score = "<input class='editScore' style='height: 100%' contenteditable='true' data-max='" + value.scoreMax + "' data-id='" + value.tScoringTableId + "'  value='" + value.score+"'/>";
                    }else{
                        var score = "<input class='editScore' style='height: 100%' contenteditable='true' data-max='" + value.scoreMax + "' data-id='" + value.tScoringTableId + "'/>"
                    }

                    value.score = score
                    value.operate = download;
                    newrow[index] = value;
                });
                result['rows'] = newrow
                // result['total'] = res.data.total

                return newrow;
            } else {
                return false;
            }

        },
        contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
        // smartDisplay: true,
        // paginationLoop: true,
        // striped: false,
        columns: [{
                field: 'areaName',
                title: '被考核单位'
            },
            {
                field: 'tScoringTableName',
                title: '考核大类'
            },
            {
                field: 'taskName',
                title: '重点任务'
            },
            {
                field: 'assessmentIndicatorsName',
                title: '考核指标'
            },
			{
                field: 'scoringMethodName',
                title: '备注'
            },
            {
                field: 'reportFinish',
                title: '是否上报'
            },
            {
                field: 'scoreMax',
                title: '分值'
            },
            {
                field: 'score',
                title: '实际考核评分'
            },
            {
                field: 'operate',
                title: '下载'
            },
        ]
    });

}

getList('', '')
$.ajax({
    type: "POST",
    url: "http://39.98.42.158/manage/getBaseServiceCount",
    // data: {username:$("#username").val(), content:$("#content").val()},
    dataType: "json",
    success: function(data) {
        var datas = data[0]
        var count = 0;
        var count1 = 0;
        if (datas.hasOwnProperty('scoreFinish')) {
            count1 = datas.scoreFinish
        }
        if (datas.hasOwnProperty('velidity')) {
            count = datas.velidity
        }
        $("#count").html(count)
        $("#count1").html(count1)
    },
    error: function(data) {

    }

});
function change(a){
    var data_max=$(a).attr('data-max')
    var data_id=$(a).attr('data-id')
    var value=$(a).attr("data-value")
    var score = "<input class='editScore' style='height: 100%' contenteditable='true' data-max='" + data_max + "' data-id='" + data_id + "' value='"+value+"' data-value='"+value+"'/>"
    $(a).parent().html(score)
}
$(document).ready(function() {

    //复选框选中
    $('.checkbox-ex input').change(function() {
        var checkboxVal = getCheckBoxVal()
        console.log(checkboxVal)
        var radioVal = getRadioVal()
        $("#table").bootstrapTable('destroy');
        getList(checkboxVal['tScoringTableName'], radioVal)
    })
    $('.radio input').change(function() {
        var checkboxVal = getCheckBoxVal()
        var radioVal = getRadioVal()
        $("#table").bootstrapTable('destroy');
        getList(checkboxVal['tScoringTableName'], radioVal)
    })

    $("#save").click(function() {
        var insert = []
        $("input.editScore").each(function() {
            var values = {}
            values.score = parseInt($(this).val())
            if (!values.score) {
                if($(this).attr('data-value')){
                    alert('录入的分数不能为空')
                    return false;
                }
            }
            values.tBaseScoreId = $(this).attr('data-id')
            var scoreMax = $(this).attr('data-max')
            if (values.score > scoreMax) {
                alert('录入的分数不能超过分值')
                return false;
            }
            insert.push(values)
        })
        $.ajax({
            type: "POST",
            url: "http://39.98.42.158/manage/updateAlId",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(insert),
            dataType: "json",
            success: function(data) {
                if (data.code == 200) {
                    window.location.reload()
                }
            },
            error: function(data) {
                window.location.reload()
            }

        });


    })

})

//{add by wuguofang 20181205 for 修复url中文乱码问题 begin
function sentMessage(searchText){		
	var searchUrl =encodeURI("http://39.98.42.158/manage/downLoadFile?" + searchText); 
	//使用encodeURI编码 
	//alert(searchUrl);
	window.location.href =searchUrl; 
}
//add by wuguofang 20181205 for 修复url中文乱码问题 end}
</script>

</html>